<?php
	class nodeControl extends Control{
		function index(){
			$db=M("node");
			$node=$db->all();
			if (!$node) {
				$this->error("还没有设置权限节点，请设置", 'add_node_show');
			}
			$node = arr::channel($node,"nid","pid",0,2,"&nbsp;&nbsp;&nbsp;&nbsp;");		
			$this->assign("node",$node);
			$this->display();
		}
	
		function add_node_show() {
			$level = isset($_GET['level']) ? $_GET['level'] : 0;
			switch ($level) {
				case 0:
					$node = array(
						array('level' => 1, 'name' => '应用'),
						array('level' => 2, 'name' => '模块控制器'),
						array('level' => 3, 'name' => '控制器方法'),
					);
					break;
				case 1:
					$node = array(
						array('level' => 2, 'name' => '模块控制器'),
						array('level' => 3, 'name' => '控制器方法'),
					);
					break;
				case 2:
					$node = array(
						array('level' => 3, 'name' => '控制器方法'),
					);
					break;
				default:
					$this->error("操作错误,当前节点已经是控制器方法，不能再添加");
			}
			$this->assign("node", $node);
			$this->display();
		}
		function add(){
			//p($_POST);
			$db=M("node");
			if($db->add()){
				$this->success("添加节点成功！","index");
			}else{
				$this->error("添加节点失败！");
			}
			
		
		}
		
		
		//删除节点
		function delnode() {
			C("debug", 1);
			$db = M("node");
			$nid = $_GET['nid'];
			if ($db->where("pid=$nid")->find()) {
				$this->error("请先删除子节点");
			}
			if ($db->del($nid)) {
				$this->success('删除成功');
			} else {
				$this->error("删除失败");
			}
		}
	}
?>